  // // 向接口添加数据
  // async function totallist(){
  //     let obj=await axios.get(hotListPreAPI)
  //     // console.log(obj);
  //     let hotArr=obj.data.Data;
  //     // console.log(hotArr);
  //     let hotListArr=hotArr.map((v)=>{
        
  //       let obj={pimg:v.FaceSrc,pname:v.Name,pprice:v.BasePriceRange,pdesc:v.ID,uid:"138133"}
  //       console.log(obj);
  //       axios.get(addProApi,{params:obj}).then((r)=>{
  //         console.log(r.data);

  //       })
  //     })

  //     }
  //     totallist()

  //     async function aaa(){
  //     axios.get("https://api5.hanfuhui.com/Product/GetProductListPublicForDefault?").then((r)=>{
  //       // console.log(r.data.Data);
  //       let obj=r.data.Data
  //       // console.log(obj);
  //       for(let key in obj){
  //         // console.log(obj[key]);
  //         let arr=obj[key]
  //         // console.log(arr);
  //         arr.forEach((v)=>{
  //           // console.log(v);
  //           let obj={pimg:v.FaceSrc,pname:v.Name,pprice:v.BasePriceRange,pdesc:v.ID,uid:"138133"}
  //           // console.log(obj.pdesc);
  //           axios.get(addProApi,{params:obj}).then((r)=>{
  //             // console.log(r.data);    
  //           })
  //         })
          
  //       }
  //     })        
  //     }
  //     aaa()

 let nav=document.querySelectorAll(".navA a")
  // console.log(nav);
  current=0;
  nav.forEach(function(v,i){
    // console.log(v,i);
    v.onclick=function(){
      // console.log(v,i);      
      nav[current].classList.remove("nav-active");
      nav[i].classList.add("nav-active");
      console.log(i);
      current=i;
  }
  })
let nextBtn=document.querySelector(".swiper-button-next")
let prevBtn=document.querySelector(".swiper-button-prev")
let banner=document.querySelector(".swiper")
banner.onmouseenter=function(){
  nextBtn.style.display="block";
  prevBtn.style.display="block";
}
banner.onmouseleave=function(){
  nextBtn.style.display="none";
  prevBtn.style.display="none";
 

}



// 轮播图
    let bannerImg=document.querySelector(".swiper-wrapper")
    // console.log(bannerImg);
    axios.get(bannerImgListAPI).then((r)=>{
      // console.log(r.data.Data);
      let arr=r.data.Data
      // console.log(arr);
      let bannerImgList=arr.map((v)=>{
        // console.log(v.ImgSrc);
        return ` <div class="swiper-slide"><img src="${v.ImgSrc}" alt=""></div>`
      })
      console.log(bannerImgList);
      bannerImg.innerHTML = bannerImgList.join('');
      
    var swiper = new Swiper(".mySwiper", {
      spaceBetween: 30,
      slidesPerView: 1,
      centeredSlides: true,
      effect: "fade",
      loop: true,
      autoplay: {
        delay: 2500,
        disableOnInteraction: false,
      },
      pagination: {
        el: ".swiper-pagination",
        clickable: true,
      },
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },

    });
    swiper.el.onmouseover = function () {
      swiper.autoplay.stop();
    }
    swiper.el.onmouseout = function () {
      swiper.autoplay.start();
    }
    })
  let uid=localStorage.getItem("id")
  
 // 判断uid如果存在跳转购物车，不存在跳转到登录页
let carExit=document.querySelector(".car")
carExit.onclick=function(){
  if(uid||Cookies.get("user") != null){
    location.href="../html/carList.html"
  }else{
    let res=window.confirm("请到登录页登录！");
    if(res){
      location.href="../html/login.html"
    }else{
      location.href="../index.html"
    }
    
  }
}
    // 本周热卖
  async function hot(){
    let obj=await axios.get(hotListPreAPI,{params:{uid:"138133"}} )
    console.log(obj);
    let hotArr=obj.data.Data;
    console.log(hotArr);
    let hotList=document.querySelector(".hot")
    let hotListArr=hotArr.map((v)=>{
      let pimg=v.FaceSrc;
      let pname= v.Name;
      let pprice=v.BasePriceRange;
      let pdesc=v.Shop.Name
      // console.log(pdesc);

      return`
        <li>
        <a href="../html/detail.html?id=${v.ID}" target="_self">
        <img src="${pimg}" alt=""></a>
        <h3><span>￥</span>${pprice}</h3>
        <a href="../html/detail.html?id=${v.ID}" target="_self">
          <p>${pname}</p>
        </a>
        </li>
      `
    })
    hotList.innerHTML=hotListArr.join('');
    
  }

  hot()


// 除热卖以外的其他；列表
  async function list(){
    let obj=await axios.get(allListAPI)
    // console.log(obj);
    let allArr=obj.data.Data ;
    console.log(allArr);
    
      // 通过键和类名添加
      for(let key in allArr){
        // console.log(allArr[key]);
        let allObjArr=allArr[key]
        let str =  renderList(allObjArr);
        document.querySelector("."+key).innerHTML=str;
      }     
  } 
  list()
  function renderList(arr){
    let allObjArrList=arr.map((v)=>{
      // console.log(v);
      let pimg=v.FaceSrc;
      // console.log(pimg);
      let pname= v.Name;
      let pprice=v.BasePriceRange;
      let pdesc=v.Shop.Name
      // console.log(pdesc);
      return`     
        <li>
          <a href="../html/detail.html?id=${v.ID}" target="_self">
          <img src="${pimg}" alt=""></a>
          <h3><span>￥</span>${pprice}</h3>
          <a href="../html/detail.html?id=${v.ID}" target="_self" ><p>${pname}</p></a>
        </li>      
    `

    })
    return allObjArrList.join('')

  }
// 回到顶部

let toTop=document.querySelector(".toTop")
toTop.onclick=function(){
  document.documentElement.scrollTo({top:0,behavior:"smooth"})
}


// 登录
let log=document.querySelector(".login")
log.onclick=function(){
  location.href="../html/login.html"
}
// 注册
let reg=document.querySelector(".reg")
reg.onclick=function(){
  location.href="../html/login.html"
}
// 跳转到自己
let self=document.querySelector(".headerImg")
self.onclick=function(){
  location.href="../index.html"
}
let token=localStorage.getItem("token")
  let loginBox=document.querySelectorAll(".login-header")
  let loginIfo=document.querySelector(".info")
  let outInfo=document.querySelector(".out")
function autoLogin(){
  
  console.log(loginBox);
  console.log(token);

  if(token||Cookies.get("user") != null){
    loginBox[0].style.display="none"
    loginBox[1].style.display="block"
    let coo=Cookies.get("user")
    if(coo!=null){
      let str = JSON.parse(coo);
      console.log(str);
      console.log(str.username);
      let ustr=str.username
      loginIfo.innerHTML=`欢迎亲爱的 `+ustr
    }else{
      let ustr=localStorage.getItem("username");
      loginIfo.innerHTML=`欢迎亲爱的 `+ustr

    }
    
    
   
  }

}

autoLogin()

outInfo.onclick=function(){
  if(Cookies.get("user")!=null){
    let str = JSON.parse(Cookies.get("user"));
    Cookies.set("user", str, { expires: 0 }); 
 }
 if(localStorage.getItem("id")){
    localStorage.clear()
 }
  
  loginBox[1].style.display="none"
  loginBox[0].style.display="block"
}